15.Interface and Application Programming

I work alone or I work alone hehe

This week the task was to create an interface that could communicate with an input or output device. For this week's group assignment, we are comparing different interface tools.

In my case, download Qt Designer, once the ideal type of canvas for our work is ready, we start working, on the left side we have the menu of components that we can add, on the right side is the breakdown of the properties of each selected Widget.

To get to know the interface a little bit, I started from something that I already had the opportunity to try, so we will use buttons for the servomotor.

what's next!

Since this application generates files with a user interface extension, we must transform them into the language of “gods”, so that they can send a signal to the Xiao that we have been using.


						from PyQt6 import QtCore, QtGui, QtWidgets
						import serial 
						from interfaz import Ui_MainWindow  # Importa la clase generada por Qt Designer
						
						class MainWindow(QtWidgets.QMainWindow):
							def __init__(self):
								super(MainWindow, self).__init__()
								self.ui = Ui_MainWindow()
								self.ui.setupUi(self)
						
								# Inicialización de serial.Serial
								self.serial = serial.Serial('COM6', 9600)
						
								# Conexión de señales y ranuras (slots)
								self.ui.On.clicked.connect(self.encender_led)
								self.ui.Off.clicked.connect(self.apagar_led)
						
							def encender_led(self):
								self.serial.write(b'1')
						
							def apagar_led(self):
								self.serial.write(b'0')
						
						if __name__ == "__main__":
							import sys
							app = QtWidgets.QApplication(sys.argv)
							mainWindow = MainWindow()
							mainWindow.show()
							sys.exit(app.exec())